﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ServerTools.Tools
{
    public class ProcessCtrl
    {
        private ProcessCtrl() { }
        public static bool CloseProcess(string processName, bool all = true)
        {
            bool succeed = false;
            try
            {
                Process[] processes = Process.GetProcesses();
                
                foreach (Process p in processes)
                {
                    Console.WriteLine(p.ProcessName);
                    if (p.ProcessName == processName)
                    {
                        p.Kill();
                        succeed = true;
                        if (all==false)
                            return succeed;
                    }
                }
            }
            catch (Exception)
            {
                return succeed;
            }
            return succeed;
        }
        public static bool CheckProcessRun(string processName)
        {
            try
            {
                Process[] processes = Process.GetProcesses();
                foreach (Process p in processes)
                {
                    if (p.ProcessName == processName)
                    {
                        return true;
                    }
                }
            }
            catch (Exception)
            {
                return false;
            }
            return false;
        }


    }
}
